package com.eclink;

import com.eclink.iot.DeviceOnlineStatusListener;
import com.eclink.iot.rfid.*;
import java.util.List;
import java.util.Scanner;

public class App {

    private final static RFIDTagDataListener rfid_tag_data_listener = (uuid, ant, epc) -> System.out.println("rfid_tag_data_listener => uuid: " + uuid + ", ant: " + ant + ", epc: " + epc);

    private final static DeviceOnlineStatusListener device_online_status_listener = (uuid, status) -> System.out.println("device_online_status_listener => uuid: " + uuid + ", status: " + status);

    public static void main(String[] args) {

        RFIDServer.set_printf(true);/* 开启日志输出 */

        RFIDServer.initialization(8087);


        RFIDServer.set_rfid_tag_data_listener(rfid_tag_data_listener);
        RFIDServer.set_device_online_status_listener(device_online_status_listener);

        boolean run = true;
        Scanner scanner = new Scanner(System.in);
        while (run) {
            String command = scanner.nextLine();

            switch (command) {
                /* 获取当前在线设备 */
                case "0": {
                    List<String> devices = RFIDServer.get_online_devices();
                    for (String device : devices) {
                        System.out.println("uuid: " + device);
                    }
                    break;
                }

                /* 重启 */
                case "1": {
                    boolean status = RFIDServer.reboot("33462E2733462E2B33462E2F");
                    System.out.println("reboot status: " + status);
                    break;
                }

                /* 单次轮询 */
                case "2": {
                    boolean status = RFIDServer.inventory("33462E2733462E2B33462E2F",
                            Antenna.NO1 | Antenna.NO2 | Antenna.NO3 | Antenna.NO4);
                            System.out.println("inventory status: " + status);
                    break;
                }

                /* 多次轮询 */
                case "3": {
                    boolean status = RFIDServer.inventory_multi("33462E2733462E2B33462E2F",
                            Antenna.NO1 | Antenna.NO2 | Antenna.NO3 | Antenna.NO4);
                            System.out.println("inventory multi status: " + status);
                    break;
                }

                /* 结束盘点 */
                case "4": {
                    boolean status = RFIDServer.stop("33462E2733462E2B33462E2F");
                    System.out.println("stop status: " + status);
                    break;
                }

                /* 升级 */
                case "5": {
                    boolean status = RFIDServer.upgrade("33462E2733462E2B33462E2F");
                    System.out.println("upgrade status: " + status);
                    break;
                }

                case "q":
                    run = false;
                    break;
            }
        }

        scanner.close();
    }
}
